package com.zhima.controller.plain;

import com.zhima.service.impl.PhoneCheckCodeServiceImpl;
import com.zhima.util.UserHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/phone")
public class PhoneController {
    @Autowired
    private PhoneCheckCodeServiceImpl phoneCheckCodeService;

    /**
     * 发送手机验证码
     *
     * @param toPhone
     * @return
     */
    @PostMapping("/{toPhone}")
    public String sendEmailCheckCode(@PathVariable("toPhone") String toPhone) {
        return phoneCheckCodeService.sendCheckCode(toPhone);
    }

    /**
     * 向登录用户发送手机验证码
     *
     * @return
     */
    @PostMapping
    public String sendPhoneCheckCode() {
        return phoneCheckCodeService.sendCheckCode(UserHolder.get().getPhone());
    }

}
